﻿#include "LimitGroupbox.h"
#include <QLabel>
#include <CircleWidget.h>
#include <QGridLayout>

LimitGroupBox::LimitGroupBox()
{
    setTitle("Limit Status");
    gridLayout = new QGridLayout(this);

    gridLayout->setSpacing(6);
    gridLayout->setContentsMargins(11, 11, 11, 11);
    gridLayout->setObjectName(QStringLiteral("gridLayout"));
    label_6 = new QLabel(this);
    label_6->setObjectName(QStringLiteral("label_6"));
    label_6->setMinimumSize(QSize(40, 0));
    label_6->setTextFormat(Qt::PlainText);
    label_6->setAlignment(Qt::AlignCenter);

    gridLayout->addWidget(label_6, 0, 1, 1, 1);

    label_7 = new QLabel(this);
    label_7->setObjectName(QStringLiteral("label_7"));
    label_7->setMinimumSize(QSize(40, 0));
    label_7->setAlignment(Qt::AlignCenter);

    gridLayout->addWidget(label_7, 0, 2, 1, 1);

    label_8 = new QLabel(this);
    label_8->setObjectName(QStringLiteral("label_8"));
    label_8->setMinimumSize(QSize(40, 0));
    label_8->setAlignment(Qt::AlignCenter);

    gridLayout->addWidget(label_8, 0, 3, 1, 1);

    label_3 = new QLabel(this);
    label_3->setObjectName(QStringLiteral("label_3"));

    gridLayout->addWidget(label_3, 1, 0, 1, 1);

    limitDisplayXL = new CircleWidget(this);
    limitDisplayXL->setObjectName(QStringLiteral("limitDisplayXL"));
    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(limitDisplayXL->sizePolicy().hasHeightForWidth());
    limitDisplayXL->setSizePolicy(sizePolicy);
    limitDisplayXL->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayXL, 1, 1, 1, 1);

    limitDisplayXHome = new CircleWidget(this);
    limitDisplayXHome->setObjectName(QStringLiteral("limitDisplayXHome"));
    sizePolicy.setHeightForWidth(limitDisplayXHome->sizePolicy().hasHeightForWidth());
    limitDisplayXHome->setSizePolicy(sizePolicy);
    limitDisplayXHome->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayXHome, 1, 2, 1, 1);

    limitDisplayXR = new CircleWidget(this);
    limitDisplayXR->setObjectName(QStringLiteral("limitDisplayXR"));
    sizePolicy.setHeightForWidth(limitDisplayXR->sizePolicy().hasHeightForWidth());
    limitDisplayXR->setSizePolicy(sizePolicy);
    limitDisplayXR->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayXR, 1, 3, 1, 1);

    label_4 = new QLabel(this);
    label_4->setObjectName(QStringLiteral("label_4"));

    gridLayout->addWidget(label_4, 2, 0, 1, 1);

    limitDisplayYL = new CircleWidget(this);
    limitDisplayYL->setObjectName(QStringLiteral("limitDisplayYL"));
    sizePolicy.setHeightForWidth(limitDisplayYL->sizePolicy().hasHeightForWidth());
    limitDisplayYL->setSizePolicy(sizePolicy);
    limitDisplayYL->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayYL, 2, 1, 1, 1);

    limitDisplayYHome = new CircleWidget(this);
    limitDisplayYHome->setObjectName(QStringLiteral("limitDisplayYHome"));
    sizePolicy.setHeightForWidth(limitDisplayYHome->sizePolicy().hasHeightForWidth());
    limitDisplayYHome->setSizePolicy(sizePolicy);
    limitDisplayYHome->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayYHome, 2, 2, 1, 1);

    limitDisplayYR = new CircleWidget(this);
    limitDisplayYR->setObjectName(QStringLiteral("limitDisplayYR"));
    sizePolicy.setHeightForWidth(limitDisplayYR->sizePolicy().hasHeightForWidth());
    limitDisplayYR->setSizePolicy(sizePolicy);
    limitDisplayYR->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayYR, 2, 3, 1, 1);

    label_5 = new QLabel(this);
    label_5->setObjectName(QStringLiteral("label_5"));

    gridLayout->addWidget(label_5, 3, 0, 1, 1);

    limitDisplayZL = new CircleWidget(this);
    limitDisplayZL->setObjectName(QStringLiteral("limitDisplayZL"));
    sizePolicy.setHeightForWidth(limitDisplayZL->sizePolicy().hasHeightForWidth());
    limitDisplayZL->setSizePolicy(sizePolicy);
    limitDisplayZL->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayZL, 3, 1, 1, 1);

    limitDisplayZHome = new CircleWidget(this);
    limitDisplayZHome->setObjectName(QStringLiteral("limitDisplayZHome"));
    sizePolicy.setHeightForWidth(limitDisplayZHome->sizePolicy().hasHeightForWidth());
    limitDisplayZHome->setSizePolicy(sizePolicy);
    limitDisplayZHome->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayZHome, 3, 2, 1, 1);

    limitDisplayZR = new CircleWidget(this);
    limitDisplayZR->setObjectName(QStringLiteral("limitDisplayZR"));
    sizePolicy.setHeightForWidth(limitDisplayZR->sizePolicy().hasHeightForWidth());
    limitDisplayZR->setSizePolicy(sizePolicy);
    limitDisplayZR->setMinimumSize(QSize(24, 24));

    gridLayout->addWidget(limitDisplayZR, 3, 3, 1, 1);

    label_6->setText("L Limit");
    label_7->setText("Home");
    label_8->setText("R Limit");
    label_3->setText("X Limit");
    label_4->setText("Y Limit");
    label_5->setText("Z Limit");

}

void LimitGroupBox::setLimitState(int axis, int llimit, int home, int rlimit)
{
    switch (axis)
    {
    case 0:
        limitDisplayXL->setState(llimit);
        limitDisplayXHome->setState(home);
        limitDisplayXR->setState(rlimit);
        break;
    case 1:
        limitDisplayYL->setState(llimit);
        limitDisplayYHome->setState(home);
        limitDisplayYR->setState(rlimit);
        break;
    case 2:
        limitDisplayZL->setState(llimit);
        limitDisplayZHome->setState(home);
        limitDisplayZR->setState(rlimit);
        break;
    default:
        break;
    }
}
